﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.Rivyer.Model;
using Com.Rivyer.BLL;
using Maticsoft.Common;

namespace Com.Rivyer.Web
{
    public partial class login : System.Web.UI.Page
    {
        private readonly userBll userbll = new userBll();
        private readonly userloginlogBll loginlogbll = new userloginlogBll();
        private readonly userlogoutlogBll logoutlogbll = new userlogoutlogBll();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["username"] != null)
            {
                Response.Redirect("~/index.html");
            }
        }

        protected void btn_login_Click(object sender, EventArgs e)
        {
                userModel usermodel = new userModel();
                usermodel.username = username.Text.Trim();
                usermodel.userpwd = userpwd.Text.Trim();
                if (userbll.ValidateUser(usermodel))
                {
                    Session["realname"] = new BLL.userinfoBll().GetModel(usermodel.username).realname;
                    Session["username"] = usermodel.username;
                    loginlogbll.AddLog(usermodel,Request.UserHostAddress,DateTime.Now);
                    Response.Redirect("~/index.html");
                }
                else
                {
                    Response.Write("<script language=\"javascript\">alert(\"用户名或者密码错误!\");</script>");
                }
        }

        protected void btn_clear_Click(object sender, EventArgs e)
        {
            //重置清空
            username.Text = "";
            userpwd.Text = "";
        }
    }
}